package com.example.playnote.viewModel

import androidx.lifecycle.MutableLiveData
import com.example.playnote.bean.BannerResponse
import com.example.playnote.bean.FriendListResponse
import com.example.playnote.bean.HomeListResponse
import com.example.playnote.bean.HotKeyResponse
import com.example.playnote.bean.TreeListResponse
import com.example.playnote.net.ApiResponse
import com.example.playnote.net.NetworkApi
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.requestNoCheck

class HomeViewModel: BaseViewModel() {
    val bannerList = MutableLiveData<ApiResponse<BannerResponse>>()
    val homeList = MutableLiveData<ApiResponse<HomeListResponse>>()
    val outSideArticle = MutableLiveData<ApiResponse<HomeListResponse>>()
    val article = MutableLiveData<ApiResponse<HomeListResponse>>()
    val likeList = MutableLiveData<ApiResponse<HomeListResponse>>()
    val searchList = MutableLiveData<ApiResponse<HomeListResponse>>()
    val typeArticleList = MutableLiveData<ApiResponse<HomeListResponse>>()
    val treeList = MutableLiveData<ApiResponse<TreeListResponse>>()
    val friendList = MutableLiveData<ApiResponse<FriendListResponse>>()
    val bookMarkList = MutableLiveData<ApiResponse<FriendListResponse>>()
    val hotKeyList = MutableLiveData<ApiResponse<HotKeyResponse>>()

    fun getBanner() {
        requestNoCheck({
            NetworkApi.service.getBanner()
        }, {
            bannerList.postValue(it)
        }, {}, false)
    }

    fun getHomeList(page: Int = 0) {
        requestNoCheck({
            NetworkApi.service.getHomeList(page)
        }, {
            homeList.postValue(it)
        }, {}, false)
    }

    fun collectOutSideArticle(title: String, author: String, link: String, isAdd: Boolean) {
        requestNoCheck({
            NetworkApi.service.addCollectOutsideArticle(title, author, link)
        }, {
            outSideArticle.postValue(it)
        }, {}, false)
    }

    fun collectArticle(page: Int = 0, isAdd: Boolean) {
        requestNoCheck({
            NetworkApi.service.addCollectArticle(page)
        }, {
            article.postValue(it)
        }, {}, false)
    }

    fun getLikeList(page: Int = 0) {
        requestNoCheck({
            NetworkApi.service.getLikeList(page)
        }, {
            likeList.postValue(it)
        }, {}, false)
    }

    fun getSearchList(page: Int = 0, k: String) {
        requestNoCheck({
            NetworkApi.service.getSearchList(page, k)
        }, {
            searchList.postValue(it)
        }, {}, false)
    }

    fun getTypeArticleList(page: Int = 0, cid: Int = 0) {
        requestNoCheck({
            NetworkApi.service.getArticleList(page, cid)
        }, {
            typeArticleList.postValue(it)
        }, {}, false)
    }

    fun getTypeTreeList() {
        requestNoCheck({
            NetworkApi.service.getTypeTreeList()
        },{
            treeList.postValue(it)
        },{}, false)
    }

    fun getFriendList() {
        requestNoCheck({
            NetworkApi.service.getFriendList()
        },{
            friendList.postValue(it)
        },{}, false)
    }

    fun getBookMark() {
        requestNoCheck({
            NetworkApi.service.getBookmarkList()
        },{
            bookMarkList.postValue(it)
        },{}, false)
    }

    fun getHotKeyList() {
        requestNoCheck({
            NetworkApi.service.getHotKeyList()
        },{
            hotKeyList.postValue(it)
        },{}, false)
    }

}